﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PdfSharp.Drawing;
using PdfSharp.Pdf;

namespace AffordoPlugin.Print
{
	public class ImgToPDF
	{
		public static Stream ImgToPDFStream(Stream imgStream)
		{
			using (var doc = new PdfDocument())
			{
				var page = doc.Pages.Add(new PdfPage());
				var img = XImage.FromStream(imgStream);


				page.Width = new XUnit(img.PointWidth, XGraphicsUnit.Point);//  img.PixelWidth+20;
				page.Height = new XUnit(img.PointHeight, XGraphicsUnit.Point);// img.PointHeight+20;

				var xgr = XGraphics.FromPdfPage(page);
				xgr.SmoothingMode = XSmoothingMode.HighQuality;

				xgr.DrawImage(img,0,0);

				doc.Save("E://ii.pdf");

				var pdfStream = new MemoryStream();

				doc.Save(pdfStream);

				return pdfStream;
			}
		}
	}
}
